package com.yb0os1.controller.user;

import com.yb0os1.dto.OrderConditionSearchDTO;
import com.yb0os1.dto.OrderSubmitDTO;
import com.yb0os1.dto.OrdersPaymentDTO;
import com.yb0os1.result.PageResult;
import com.yb0os1.result.Result;
import com.yb0os1.serve.OrderServe;
import com.yb0os1.vo.OrderPaymentVO;
import com.yb0os1.vo.OrderSubmitVO;
import com.yb0os1.vo.OrderVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController("userOrderController")
@RequestMapping("/user/order")
@Tag(name = "用户端订单相关接口")
@Slf4j
public class OrderController {
    @Autowired
    private OrderServe orderServe;

    @Operation(summary = "用户下单")
    @PostMapping("/submit")
    public Result<OrderSubmitVO> submitOrder(@RequestBody OrderSubmitDTO orderSubmitDTO){
        return Result.success(orderServe.submit(orderSubmitDTO));
    }
    /**
     * 订单支付
     *
     * @param ordersPaymentDTO
     * @return
     */
    @PutMapping("/payment")
    @Operation(summary = "订单支付")
    public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
       /* log.info("订单支付：{}", ordersPaymentDTO);
        OrderPaymentVO orderPaymentVO = orderServe.payment(ordersPaymentDTO);
        log.info("生成预支付交易单：{}", orderPaymentVO);
        return Result.success(orderPaymentVO);*/
        //模拟一下支付成功 直接修改数据库的状态
        return Result.success(orderServe.payment(ordersPaymentDTO));
    }

    @Operation(summary = "查看历史订单")
    @GetMapping("/historyOrders")
    public Result<PageResult> getHistoryOrders(OrderConditionSearchDTO orderConditionSearchDTO){
        return Result.success(orderServe.getHistoryOrders(orderConditionSearchDTO));
    }


    @Operation(summary = "查询订单详情")
    @GetMapping("/orderDetail/{id}")
    public Result<OrderVO> getDetail(@PathVariable Long id){
        return Result.success(orderServe.getOrderById(id));
    }
    @Operation(summary = "取消订单")
    @PutMapping("/cancel/{id}")
    public Result cancelOrder(@PathVariable Long id){
        orderServe.cancelOrder(id);
        return Result.success();
    }

    @Operation(summary = "再来一单")
    @PostMapping("/repetition/{id}")
    public Result repetitionOrder(@PathVariable Long id){
        orderServe.repetitionOrder(id);
        return Result.success();
    }

    @Operation(summary = "用户催单")
    @GetMapping("/reminder/{id}")
    public Result reminderOrder(@PathVariable Long id){
        orderServe.reminderOrder(id);
        return Result.success();
    }
}
